<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\logic;



use app\common\model\InterestAllocation;

/**
 * 利息配置逻辑
 */
class Interest extends AdminBase
{



    /**
     * 获取利息配置列表
     */
    public function getInterestList($where = [], $field = 'a.*', $order = '')
    {

        $this->modelInterestAllocation->alias('a');

        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];
        $count=$this->modelInterestAllocation->alias('a')->where($where)->count();

        $list=$this->modelInterestAllocation->alias('a')->field($field)->where($where)->paginate(50);

        return ['list'=>$list,'count'=>$count];
    }



    /**
     * 获取利息配置列表搜索条件
     */
    public function getWhere($data = [])
    {

        $where = [];

       if(!empty($data['id'])){
           $where['id']=$data['id'];
       }
        !empty($data['type']) && $where['type']=$data['type'];
        return $where;
    }




    /**
     * 利息配置信息编辑
     */
    public function InterestEdit($data = [])
    {


        $url = url('InterestList');

        $data['type']==2 &&   $url = url('InterestList1');
        if(  empty($data['money'])){
            return [RESULT_ERROR, '金额不能为空'];
        }
        $where=['type'=>2,'status'=>1,'id'=>['lt',$data['id']+1]];
        $data['collection_money_total']=InterestAllocation::where($where)->sum('collection_money');
        $data['substitute_money_total']=InterestAllocation::where($where)->sum('substitute_money');
        $data['collection_count_total']=InterestAllocation::where($where)->sum('collection_count');
        $data['substitute_count_total']=InterestAllocation::where($where)->sum('substitute_count');
        $data['feed_count_total']=InterestAllocation::where($where)->sum('feed_count');
        $result = $this->modelInterestAllocation->setInfo($data);
        $handle_text = empty($data['id']) ? '新增' : '编辑';

        $result && action_log($handle_text, '利息配置' );

        return $result ? [RESULT_SUCCESS, '利息配置操作成功', $url] : [RESULT_ERROR, '没有修改'];
    }

    /**
     * 获取利息配置信息
     */
    public function getInterestInfo($where = [], $field = 'a.*')
    {

        $this->modelInterestAllocation->alias('a');


        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];


        return $this->modelInterestAllocation->getInfo($where, $field);
    }

 










}
